package com.gscitysfy.cus.drain.modules.command.convert;

import com.gscitysfy.cus.drain.modules.command.dto.ReservePlanManageDto;
import com.gscitysfy.cus.drain.modules.command.entity.ReservePlanManage;
import com.gscitysfy.cus.drain.modules.common.entity.DrainInspectionMnFile;
import com.gscitysfy.cus.drain.modules.common.mapper.DrainInspectionMnFileMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Author jiang_wen
 * @Date 2022/10/22 11:25
 * @Description TODO
 */
@AllArgsConstructor
@Component
public class ReservePlanManageConvert {

    private final DrainInspectionMnFileMapper fileMapper;

    public ReservePlanManage toEntity(ReservePlanManage reservePlanManage, ReservePlanManageDto reservePlanManageDto) {
        reservePlanManage.setName(reservePlanManageDto.getName());
        reservePlanManage.setGrade(reservePlanManageDto.getGrade());
        reservePlanManage.setType(reservePlanManageDto.getType());
        reservePlanManage.setEnableStatus(reservePlanManageDto.getEnableStatus());
        reservePlanManage.setFileId(reservePlanManageDto.getFileId());
        reservePlanManage.setManagementUnit(reservePlanManageDto.getManagementUnit());
        reservePlanManage.setPersonLiable(reservePlanManageDto.getPersonLiable());
        reservePlanManage.setOrganizePrepare(reservePlanManageDto.getOrganizePrepare());
        reservePlanManage.setProjectPrepare(reservePlanManageDto.getProjectPrepare());
        reservePlanManage.setReservePlanPrepare(reservePlanManageDto.getReservePlanPrepare());
        reservePlanManage.setMaterialPrepare(reservePlanManageDto.getMaterialPrepare());
        reservePlanManage.setCommunicationPrepare(reservePlanManageDto.getCommunicationPrepare());
        return reservePlanManage;
    }

    public ReservePlanManageDto toDto(ReservePlanManage reservePlanManage) {
        ReservePlanManageDto reservePlanManageDto = new ReservePlanManageDto();
        reservePlanManageDto.setCmKid(reservePlanManage.getCmKid());
        reservePlanManageDto.setName(reservePlanManage.getName());
        reservePlanManageDto.setGrade(reservePlanManage.getGrade());
        reservePlanManageDto.setType(reservePlanManage.getType());
        reservePlanManageDto.setEnableStatus(reservePlanManage.getEnableStatus());
        reservePlanManageDto.setFileId(reservePlanManage.getFileId());
        if (Objects.nonNull(reservePlanManage.getFileId())) {
            DrainInspectionMnFile drainInspectionMnFile = fileMapper.selectById(reservePlanManage.getFileId());
            if (Objects.nonNull(drainInspectionMnFile)) {
                reservePlanManageDto.setFileName(drainInspectionMnFile.getCmFileName());
            }
        }
        reservePlanManageDto.setManagementUnit(reservePlanManage.getManagementUnit());
        reservePlanManageDto.setPersonLiable(reservePlanManage.getPersonLiable());
        reservePlanManageDto.setOrganizePrepare(reservePlanManage.getOrganizePrepare());
        reservePlanManageDto.setProjectPrepare(reservePlanManage.getProjectPrepare());
        reservePlanManageDto.setReservePlanPrepare(reservePlanManage.getReservePlanPrepare());
        reservePlanManageDto.setMaterialPrepare(reservePlanManage.getMaterialPrepare());
        reservePlanManageDto.setCommunicationPrepare(reservePlanManage.getCommunicationPrepare());
        return reservePlanManageDto;
    }
}
